package com.scedu.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletMapping;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@Controller
public class ResultGo {
    //通过HttpServletResponse 进行输出
    @RequestMapping("/result/t1")
    public void test1(HttpServletResponse response, HttpServletRequest request) throws IOException {
        response.getWriter().print("hello ,spring by servlet API");
    }

    //通过HttpServletResponse实现重定向
    @RequestMapping("/result/t2")
    public void test2(HttpServletResponse response, HttpServletRequest request) throws IOException {
        response.sendRedirect("/hello");
    }

    //通过HttpServletResponse 实现转发
    @RequestMapping("/result/t3")
    public void test3(HttpServletResponse response, HttpServletRequest request) throws IOException, ServletException {
        request.setAttribute("msg","value is hello");
        request.getRequestDispatcher("/WEB-INF/jsp/hello.jsp").forward(request,response);
    }
}
